const app = getApp();
const http = require('../../../utils/http.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    TabCur: 1,
    SortMenu: [{id: 1, name: "未使用"}, {id: 2, name: "已使用"}, {id: 3, name: "已过期"}],
    couponList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let postData = {status: this.data.TabCur}
    this.selectCouponList(postData)
  },

  selectCouponList(data) {
    http.get('/api/user/selectMyCouponList', data).then(res => {
      if (res.code == 200) {
        this.setData({
          couponList: res.result
        })
      }
    })
  },

  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id
    })
    let postData = {status: e.currentTarget.dataset.id}
    this.selectCouponList(postData)
  },

  couponClick(e) {
    let index = e.currentTarget.dataset.index
    let coupon = this.data.couponList[index];
    if (coupon.stockType == 'merNORMAL' && coupon.status == 1) {
      wx.navigateTo({
        url: "/pages/user/mycoupon/qrcode?name=" + coupon.stockName + "&code=" + coupon.couponCode + "&id=" + coupon.id
      })
    }
  }

})
